home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amiga / visualarts / source / appmenu / appmenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-02  |  6.5 KB  |  278 lines

  1. /* ******************************************************************** */
  2. /* C code generated by:                            */
  3. /* Visual Arts Version 2.1                        */
  4. /* Copyright 1994-95 Danny Y. Wong  All rights reserved            */
  5. /* Calgary, Alberta (CANADA)                                    */
  6. /* Partial of the code is copyright by Jaba Development            */
  7. /* ******************************************************************** */
  8.  
  9. #include <VisualArts.h>
  10. #include <clib/VisualArts_protos.h>
  11.  
  12. #define ID_ObjID1                                     0
  13.  
  14. #define AppMenuNumGads                        1
  15.  
  16. #include "AppMenu_func.c" 
  17.  
  18. int ObjID1Obj(struct VAobject VAObject);
  19.  
  20. int GetPubScreen(void);
  21. void ClosePubScreen(void);
  22. int OpenAppMenuWindow(char windtitle[]);
  23. void CloseAppMenuWindow(void);
  24. int AppMenuHandler(void);
  25. int AppMenuMainHandler(void);
  26. extern int AppMenuAppWindHandler(struct MsgPort *appwindport);
  27. void DrawAppMenuObjs(void);
  28. int main(int argc, char *argv[]);
  29.  
  30. UBYTE                *PubScrName = "Workbench";
  31. struct DrawInfo            *ScrDrawInfo = NULL;
  32. APTR                 VisualInfo = NULL;
  33. struct Screen            *Scr = NULL;
  34. struct Window            *AppMenuWnd = NULL;
  35. struct AppWindow        *AppMenuAppWind = NULL;
  36. struct MsgPort            *AppMenuAppWindPort = NULL;
  37. struct Gadget            *AppMenuGList = NULL;
  38. struct Gadget            *AppMenuGadgets[AppMenuNumGads];
  39. struct IntuiMessage         AppMenuMsg;
  40. UWORD                 AppMenuLeft = 157;
  41. UWORD                 AppMenuTop = 53;
  42. UWORD                 AppMenuWidth = 224;
  43. UWORD                 AppMenuHeight = 50;
  44. struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  45. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  46.  
  47. struct IntuiText AppMenuIText[] = {
  48.   1, 0, JAM2, 25, 3, &topaz800, (UBYTE *)"Drag icons into window.", NULL,
  49. };
  50.  
  51. WORD AppMenuGadTypes[] = {
  52.     BUTTON_KIND,
  53. };
  54.  
  55. struct NewGadget AppMenuNGads[] = {
  56.     59, 15, 90, 15, (UBYTE *)"Quit",&topaz800, ID_ObjID1, PLACETEXT_IN, NULL, (APTR)ObjID1Obj,
  57. };
  58.  
  59. ULONG AppMenuNTags[] = {
  60.     TAG_DONE,
  61. };
  62.  
  63.  
  64. int GetPubScreen(void)
  65. {
  66.   if (!(Scr = LockPubScreen(PubScrName)))
  67.     return(1L);
  68.  
  69.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  70.     return(2L);
  71.  
  72.   if (!(ScrDrawInfo = GetScreenDrawInfo(Scr)))
  73.     return(3L);
  74.   return(0L);
  75. }
  76.  
  77. void ClosePubScreen(void)
  78. {
  79.   if (VisualInfo)
  80.     FreeVisualInfo(VisualInfo);
  81.   if (Scr)
  82.     UnlockPubScreen(NULL,  Scr);
  83.   if (ScrDrawInfo)
  84.     FreeScreenDrawInfo(Scr,  ScrDrawInfo);
  85. }
  86.  
  87. int OpenAppMenuWindow(char windtitle[80])
  88. {
  89.   struct NewGadget    NewGad;
  90.   struct Gadget       *Gad;
  91.   register UWORD i, j;
  92.   UWORD offsetx = Scr->WBorLeft;
  93.   UWORD offsety = Scr->WBorTop + Scr->Font->ta_YSize + 1;
  94.  
  95.   if (!(Gad = CreateContext(&AppMenuGList)))
  96.       return(1L);
  97.  
  98.   for (i=0, j=0; i < AppMenuNumGads; i++)
  99.   {
  100.     CopyMem((char *)&AppMenuNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  101.  
  102.     NewGad.ng_VisualInfo = VisualInfo;
  103.     NewGad.ng_LeftEdge += offsetx;
  104.     NewGad.ng_TopEdge  += offsety;
  105.  
  106.     AppMenuGadgets[i] = Gad = CreateGadgetA((ULONG)AppMenuGadTypes[i], Gad, &NewGad,
  107.     (struct TagItem *)&AppMenuNTags[j]);
  108.     while (AppMenuNTags[j])
  109.         j +=2;
  110.     j++;
  111.     if (!Gad)
  112.        return(2L);
  113.   }
  114.   if (!(AppMenuWnd = OpenWindowTags(NULL,
  115.       WA_Left,    AppMenuLeft,
  116.       WA_Top,     AppMenuTop,
  117.       WA_Width,    AppMenuWidth,
  118.       WA_Height,    AppMenuHeight + kWindowOffSetY,
  119.       WA_NewLookMenus, TRUE,
  120.       WA_IDCMP,    IDCMP_CLOSEWINDOW | IDCMP_GADGETUP ,
  121.       WA_Flags,    WFLG_CLOSEGADGET  |  WFLG_SMART_REFRESH | 
  122.              WFLG_RMBTRAP |  WFLG_ACTIVATE | 
  123.              WFLG_DRAGBAR ,
  124.       WA_Gadgets,    AppMenuGList,
  125.       WA_Title,    windtitle,
  126.       WA_ScreenTitle,    "Visual Arts V2.2 Copyright 1994-95 Danny Y. Wong  All Rights Reserved.",
  127.       WA_PubScreen,    Scr,
  128.       WA_MinWidth,    160,
  129.       WA_MinHeight,    50,
  130.       WA_MaxWidth,    640,
  131.       WA_MaxHeight,    200,
  132.       TAG_DONE)))
  133.           return(3L);
  134.  
  135.   if (AppMenuAppWindPort = CreateMsgPort())
  136.   {
  137.     AppMenuAppWind = AddAppWindow(1, 0, AppMenuWnd, AppMenuAppWindPort, NULL);
  138.     if (AppMenuAppWind == NULL)
  139.     {
  140.       CloseAppMenuWindow();
  141.       return(-1L);
  142.     }
  143.   }
  144.   else
  145.     return(-2L);
  146.   DrawAppMenuObjs();
  147.   GT_RefreshWindow(AppMenuWnd, NULL);
  148.   RefreshGadgets(AppMenuGadgets[0], AppMenuWnd, NULL);
  149.   return(0L);
  150. }
  151.  
  152. void CloseAppMenuWindow(void)
  153. {
  154.   struct AppMessage *appwindmsg;
  155.  
  156.   if (AppMenuWnd)
  157.     CloseWindow(AppMenuWnd);
  158.   if (AppMenuGList)
  159.     FreeGadgets(AppMenuGList);
  160.   if (AppMenuAppWind)
  161.   {
  162.     RemoveAppWindow(AppMenuAppWind);
  163.     while (appwindmsg = (struct AppMessage *)GetMsg(AppMenuAppWindPort))
  164.         ReplyMsg((struct Message *)appwindmsg);
  165.     DeleteMsgPort(AppMenuAppWindPort);
  166.   }
  167. }
  168.  
  169. int AppMenuHandler(void)
  170. {
  171.   struct IntuiMessage    *msg;
  172.   struct VAobject    VAObject;
  173.   int running    = 1;
  174.   int (*func)(struct VAobject VAObject);
  175.   ULONG class;
  176.   UWORD code;
  177.  
  178.   while (msg=GT_GetIMsg(AppMenuWnd->UserPort))
  179.   {
  180.     CopyMem((char *)msg, (char *)&AppMenuMsg, (long)sizeof(struct IntuiMessage));
  181.     class = msg->Class;
  182.     code  = msg->Code;
  183.  
  184.     VAObject.va_Window = (struct Window *)AppMenuWnd;
  185.     VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  186.     VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  187.     VAObject.va_Flags = 0;
  188.     VAObject.va_UserData = 0;
  189.  
  190.     GT_ReplyIMsg(msg);
  191.     switch(class)
  192.     {
  193.  
  194.       case IDCMP_CLOSEWINDOW:
  195.          return(0);
  196.          break;
  197.  
  198.       case IDCMP_GADGETUP:
  199.         func = (void *)((struct Gadget *)AppMenuMsg.IAddress)->UserData;
  200.         if (func != NULL)
  201.           running =  func(VAObject);
  202.         break;
  203.  
  204.     }
  205.   }
  206.   return(running);
  207. }
  208.  
  209. void DrawAppMenuObjs(void)
  210. {
  211.   PrintIText(AppMenuWnd->RPort, AppMenuIText, AppMenuWnd->BorderLeft, AppMenuWnd->BorderTop);
  212.  
  213. }
  214.  
  215. int AppMenuAppWindHandler(struct MsgPort *appwindport)
  216. {
  217.   struct WBArg    *wbargptr;
  218.   struct AppMessage    *appwindmsg;
  219.   int i;
  220.  
  221.   while (appwindmsg = (struct AppMessage *)GetMsg(appwindport))
  222.   {
  223.     wbargptr = appwindmsg->am_ArgList;
  224.  
  225.     /*  examine the icons dragged into the window here.   */ 
  226.     /*  wbargptr->wa_Name ---> name of the icon           */ 
  227.     /*  wbargptr->wa_Lock ---> directory this icon is in. */ 
  228.  
  229.     for (i=0; i < appwindmsg->am_NumArgs; i++)
  230.     {
  231.            printf("Icon name %s\n", wbargptr->wa_Name);
  232.        wbargptr++;
  233.     }
  234.     ReplyMsg((struct Message *)appwindmsg);
  235.   }
  236.   return(0);
  237. }
  238.  
  239. int AppMenuMainHandler(void)
  240. {
  241.   int running = 1;
  242.   ULONG windsig, signals;
  243.  
  244.   ULONG appwindsig;
  245.  
  246.   appwindsig = 1L << AppMenuAppWindPort->mp_SigBit;
  247.   windsig = 1L << AppMenuWnd->UserPort->mp_SigBit;
  248.  
  249.   while (running == 1)
  250.   {
  251.     signals = Wait( windsig | appwindsig );
  252.     if (signals & windsig)
  253.     {
  254.       running = AppMenuHandler();
  255.     }
  256.     else
  257.     if (signals & appwindsig)
  258.       AppMenuAppWindHandler(AppMenuAppWindPort);
  259.   }
  260.   return(running);
  261. }
  262.  
  263. int main(int argc, char *argv[])
  264. {
  265.   int rc;
  266.  
  267.   if (!(GetPubScreen()))
  268.   {
  269.     if (!(OpenAppMenuWindow("AppMenu Demo")))
  270.     {
  271.       rc = AppMenuMainHandler();
  272.       CloseAppMenuWindow();
  273.     }
  274.     ClosePubScreen();
  275.   }
  276.   return(0L);
  277. }
  278.